package org.yunai.swjg.server.rpc.struct;

import org.yunai.yfserver.message.*;

/**
 * 竞技场挑战记录
 */
public class StChallengeHistory implements IStruct {
    /**
     * 是否主动攻击
     */
    private Byte active;
    /**
     * 战报编号
     */
    private Integer id;
    /**
     * 昵称
     */
    private String nickname;
    /**
     * 是否胜利
     */
    private Byte win;

    public StChallengeHistory() {
    }

    public StChallengeHistory(Byte active, Integer id, String nickname, Byte win) {
        this.active = active;
        this.id = id;
        this.nickname = nickname;
        this.win = win;
    }

	public Byte getActive() {
		return active;
	}

	public void setActive(Byte active) {
		this.active = active;
	}
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}
	public Byte getWin() {
		return win;
	}

	public void setWin(Byte win) {
		this.win = win;
	}

    public static class Decoder extends AbstractDecoder {
        private static Decoder decoder = new Decoder();

        public static Decoder getInstance() {
            return decoder;
        }

        public IStruct decode(ByteArray byteArray) {
            StChallengeHistory struct = new StChallengeHistory();
            struct.setActive(byteArray.getByte());
            struct.setId(byteArray.getInt());
            struct.setNickname(getString(byteArray));
            struct.setWin(byteArray.getByte());
            return struct;
        }
    }

    public static class Encoder extends AbstractEncoder {
        private static Encoder encoder = new Encoder();

        public static Encoder getInstance() {
            return encoder;
        }

        public ByteArray encode(IStruct message) {
            StChallengeHistory struct = (StChallengeHistory) message;
            ByteArray byteArray = ByteArray.createNull(6);
            byte[] nicknameBytes = convertString(byteArray, struct.getNickname());
            byteArray.create();
            byteArray.putByte(struct.getActive());
            byteArray.putInt(struct.getId());
            putString(byteArray, nicknameBytes);
            byteArray.putByte(struct.getWin());
            return byteArray;
        }
    }
}